package hu.uniobuda.nik.bsik2f;

import com.un4seen.bass.BASS;

public class MediaFile {
	String filePath;
	int stream;

	public String getPath() {
		return filePath;
	}

	public int getStream() {
		return BASS.BASS_StreamCreateFile(filePath, 0, 0,
				BASS.BASS_STREAM_PRESCAN | BASS.BASS_STREAM_AUTOFREE);
	}

	public double getTotalTimeSeconds() {
		return BASS.BASS_ChannelBytes2Seconds(this.stream,
				BASS.BASS_ChannelGetLength(this.stream, BASS.BASS_POS_BYTE));
	}

	public double getElapsedTimeSeconds() {
		return BASS.BASS_ChannelBytes2Seconds(this.stream,
				BASS.BASS_ChannelGetPosition(this.stream, BASS.BASS_POS_BYTE));
	}

	public long getTotalTimeBytes() {
		return BASS.BASS_ChannelGetLength(this.stream, BASS.BASS_POS_BYTE);
	}

	public long getElapsedTimeBytes() {
		return BASS.BASS_ChannelGetPosition(this.stream, BASS.BASS_POS_BYTE);
	}

	public int getStatus() {
		return BASS.BASS_ChannelIsActive(this.stream);
	}

	@Override
	public String toString() {
		TagInfo tags = new TagInfo(filePath);
		return String.format("{0} - {1} [{2}]", tags.artist, tags.title,
				tags.duration);
	}

	public void Play() {
		Stop();
		this.stream = BASS.BASS_StreamCreateFile(filePath, 0, 0,
				BASS.BASS_STREAM_PRESCAN | BASS.BASS_STREAM_AUTOFREE);
		BASS.BASS_ChannelPlay(stream, true);
	}

	public void Stop() {
		BASS.BASS_ChannelStop(stream);
		BASS.BASS_SampleFree(stream);
	}
}
